/**
 * 
 */
package no.ntnu.item.ttm4115.termproject.callhelprole_playeragent.gui;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import no.ntnu.item.ttm4115.termproject.AcceptHelpReq;
import no.ntnu.item.ttm4115.termproject.DeclineHelpReq;
import no.tellu.common.actorframe.ActorSM;
import no.tellu.common.javaframe.messages.ActorMsg;
import no.ntnu.item.ttm4115.termproject.callhelprole_playeragent.CallhelpRole_PlayerAgentSM;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * @author item
 *
 */
public class PopUp extends JFrame{
	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}	
	
    private static ActorSM asm;
    public ActorSM getAsm() {
		return asm;
	}
    private JButton accept;
    private JButton reject;
    private JLabel shortMessage;
    private JPanel popupWindow;
    private static String msg = "Standard";
    
    public PopUp() {
        init();
        this.pack();
        this.setAlwaysOnTop(true);
        this.setBounds(0, 0, 250, 100);
        this.setTitle("Help request");
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /**
     * Initialiser.
     */
    private void init() {
    	accept = new JButton("Accept");
    	reject = new JButton("Reject");
    	popupWindow = new JPanel();
    	
    	popupWindow.setToolTipText("Help request");
    	
    	accept.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // accept action
        		asm.sendMessage(new AcceptHelpReq(), asm.getMyActorAddress());
        		popupWindow.setVisible(false);
            }
        });
    	reject.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // reject action
        		asm.sendMessage(new DeclineHelpReq(), asm.getMyActorAddress());
        		popupWindow.setVisible(false);
            }
        });

        // add components to main panel
        popupWindow.setLayout(null);
        {
        	shortMessage = new JLabel("Description");
        	popupWindow.add(shortMessage);
        	FlowLayout shortMessageLayout = new FlowLayout();
        	shortMessage.setLayout(shortMessageLayout);
        	shortMessage.setText(getMessageContent());
        	shortMessage.setPreferredSize(new java.awt.Dimension(242, 20));
        	shortMessage.setBounds(5, 5, 242, 20);
        }
        popupWindow.add(accept);
        accept.setPreferredSize(new java.awt.Dimension(33, 30));
        accept.setBounds(121, 25, 120, 30);
        popupWindow.add(reject);
        reject.setPreferredSize(new java.awt.Dimension(33, 30));
        reject.setBounds(1, 25, 120, 30);
        this.getContentPane().add(popupWindow);
        // use frame

 


    }

    /**
	 * @return
	 */
	private String getMessageContent() {
		// 
		//reserved message label that displaying the requester's short description of the
		// help content
		return msg;
	}

	public static void main(String[] args, CallhelpRole_PlayerAgentSM actorsm) {
        if (args[0] != null) {
        	msg = args[0];
        }
        asm = actorsm;
        PopUp a = new PopUp();
    }
	
}
